//
//  QPJHTool.m
//  QPJHLightSDK
//
//  Created by qply on 2021/4/26.
//  Copyright © 2021 Vanney. All rights reserved.
//

#import "SQPJHTool.h"
#import "SQPJHNetworkManager.h"
#import "QPJHUrlHeader.h"
#import "QPJHFunDataFormat.h"
#import "QPJHFunRoleModel.h"
#import "QPConstHeader.h"
#import "QPSaccountStore.h"
#import "UIView+Toast.h"

@interface SQPJHTool ()
@property(nonatomic, strong) QPJSuperRoleModel *roleinfo;

@end

@implementation SQPJHTool
- (NSMutableDictionary *)mDict {
    if (_mDict == nil) {
        _mDict = @{}.mutableCopy;
    }
    return _mDict;
}


- (void)qpSetNoticeViewWithPlatform_ID:(NSString *)platform_id SuccessBlock:(QPJHSuccessHandle)successBlock FailureBlock:(QPJHFailureHandle)failBlock {
    
    NSDictionary *dic1 = @{
                           @"platform_id":platform_id,
                           @"game_id":[QPJHFunDataFormat QPJHGetGameID],
                           @"os_type":@"2",
                           };
    [SQPJHNetworkManager PostWithURL:@"https://supersdk.7pa.com/init" Params:dic1 success:^(id responseObject) {
        NSDictionary *surperdic = (NSDictionary *)responseObject;
        NSString *surpercode = [NSString stringWithFormat:@"%@",surperdic[@"code"]];
        if ([surpercode isEqualToString:@"200"]) {
            successBlock(surperdic);
        }
        
    } failure:^(NSString *error) {
        failBlock(error);
    }];
}


- (void)qpjh_canEnterGameWithServiceID:(NSString *)service_id ServiceName:(NSString *)service_name User_id:(NSString *)user_id SuccessBlock:(QPJHSuccessHandle)successBlock FailureBlock:(QPJHFailureHandle)failBlock {
    
    
    NSDictionary *params = @{
                            @"game_id":[QPJHFunDataFormat QPJHGetGameID],
                            @"super_user_id":user_id,
                            @"service_id":service_id,
                            @"service_name":service_name,
                            };
    [SQPJHNetworkManager PostWithURL:@"https://supersdk.7pa.com/login/enter" Params:params success:^(id responseObject) {
        NSString *code = [NSString stringWithFormat:@"%@", responseObject[@"code"]];
        NSString *msg = [NSString stringWithFormat:@"%@", responseObject[@"msg"]];
        if ([code isEqualToString:SuccessCode]) {

            successBlock(@"1");
        } else {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                [[[QPSaccountStore sharedInstance] getCurrentWindow] makeToast:msg];
            });
            failBlock(@"0");
        }
        
    } failure:^(NSString *error) {
        failBlock(error);
    }];
}

@end
